package cn.stylefeng.guns.modular.transport.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.rest.transport.vo.StoreInfo;
import cn.stylefeng.guns.modular.transport.entity.InwarehouseTrack;
import cn.stylefeng.guns.modular.transport.mapper.InwarehouseTrackMapper;
import cn.stylefeng.guns.modular.transport.model.params.InwarehouseTrackParam;
import cn.stylefeng.guns.modular.transport.model.result.InwarehouseTrackResult;
import  cn.stylefeng.guns.modular.transport.service.InwarehouseTrackService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 到仓跟踪 服务实现类
 * </p>
 *
 * @author wp
 * @since 2025-04-19
 */
@Service
public class InwarehouseTrackServiceImpl extends ServiceImpl<InwarehouseTrackMapper, InwarehouseTrack> implements InwarehouseTrackService {

    @Autowired
    private InwarehouseTrackMapper inwarehouseTrackMapper;
    @Override
    public void add(InwarehouseTrackParam param){
        InwarehouseTrack entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(InwarehouseTrackParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(InwarehouseTrackParam param){
        InwarehouseTrack oldEntity = getOldEntity(param);
        InwarehouseTrack newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public InwarehouseTrackResult findBySpec(InwarehouseTrackParam param){
        return null;
    }

    @Override
    public List<InwarehouseTrackResult> findListBySpec(InwarehouseTrackParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(InwarehouseTrackParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public void uploadPoint(InwarehouseTrackParam inwarehouseTrackParam) {
        InwarehouseTrack entity = getEntity(inwarehouseTrackParam);

        this.save(entity);

    }

    @Override
    public StoreInfo getStoreInfoByClientVolSumId(Long clientVolSumId) {
        return inwarehouseTrackMapper.getStoreInfoByClientVolSumId(clientVolSumId);
    }

    @Override
    public LayuiPageInfo  findHx_daocanggenzong(InwarehouseTrackParam inwarehouseTrackParam, String condition, String startTime, String endTime, Long operateId) {
//        return inwarehouseTrackMapper.findHx_daocanggenzong(inwarehouseTrackParam, condition, startTime, endTime, operateId);
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findHx_daocanggenzong(pageContext, inwarehouseTrackParam, condition, startTime, endTime, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(InwarehouseTrackParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private InwarehouseTrack getOldEntity(InwarehouseTrackParam param) {
        return this.getById(getKey(param));
    }

    private InwarehouseTrack getEntity(InwarehouseTrackParam param) {
        InwarehouseTrack entity = new InwarehouseTrack();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
